package cn.zhibang.sannuo.maintenance.api;

import cn.zhibang.sannuo.commons.model.CommonResult;
import cn.zhibang.sannuo.commons.model.Cudetails;
import cn.zhibang.sannuo.commons.model.Menu;
import cn.zhibang.sannuo.commons.model.Role;
import cn.zhibang.sannuo.maintenance.service.MCheckUpService;
import cn.zhibang.sannuo.maintenance.service.MenuService;
import cn.zhibang.sannuo.maintenance.service.RoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName MaintenanceApi.java
 * @Description TODO
 * @createTime 2021年03月29日 16:23:00
 */
@RestController
public class MaintenanceApi {

    @Autowired private CommonResult commonResult;
    @Autowired private RoleService roleService;
    @Autowired private MenuService menuService;
    @Autowired private MCheckUpService mCheckUpService;

    @PostMapping("/getRoleAll")
    @ApiOperation("获得全部角色信息")
    public CommonResult getRoleAll(){
        List<Role> roles = roleService.selAllRole();
        commonResult.setData(roles);
        return commonResult;
    }

    @PostMapping("/upRole")
    @ApiOperation("修改角色信息")
    public CommonResult upRoleAll(Role role){
        roleService.upRole(role);
        return commonResult;
    }

    @PostMapping("/getMenuAll")
    @ApiOperation("获得全部菜单信息")
    public CommonResult getMenuAll(){
        List<Menu> menuList = menuService.selAllMenu();
        commonResult.setData(menuList);
        return commonResult;
    }

    @PostMapping("/upMenu")
    @ApiOperation("修改菜单信息")
    public void upMenu(Menu menu){
        if (menu.getComment() == "")menu.setComment(null);
        menuService.upMenu(menu);
    }

    @PostMapping("/getAllCheckUpCuid")
    @ApiOperation("获得体检项目信息")
    public CommonResult getAllCheckUpCuid(Integer cuid){
        if (cuid!=null && 0 == cuid) cuid = null;
        List<Cudetails> cudetails = mCheckUpService.selAllCudetails(cuid);
        commonResult.setData(cudetails);
        return commonResult;
    }

}
